import java.io.IOException;
import java.util.LinkedList;

import twitter4j.StallWarning;
import twitter4j.Status;
import twitter4j.StatusDeletionNotice;
import twitter4j.StatusListener;
import twitter4j.TwitterException;
import twitter4j.TwitterStream;
import twitter4j.TwitterStreamFactory;
import twitter4j.auth.AccessToken;

/**
 *
 * Authenticates with the Twitter.
 *
 * @author Adas Burksaitis
 */
public abstract class Stream {

	TwitterStream stream;

	public Stream() {
	    stream = new TwitterStreamFactory().getInstance();
	}

	/**
	 * Initializes a real time connection to Twitter.
	 *
	 */
	public void connect() {
	    stream.setOAuthConsumer("ytBPDk6XCrIq0g6xxL1Zp9oDo", "RwX7l8WMG96CIz37brkQowWCtHlVJm2JqaY8mH5K21YnYX10l2");
		AccessToken accessToken = new AccessToken("2412669103-cFOFXcKnrIGdH7Lka6MDLRi2krwEdtoqKb8rmRR", 
		  "BydP3KYFYaI0pKgcfM9PZMsQLKY1KoAf4Oj5btfFpMEqw");
		stream.setOAuthAccessToken(accessToken);
	}
	
	public static void main(String[] args) throws TwitterException, IOException{
	    StatusListener listener = new StatusListener(){
	        public void onStatus(Status status) {
	            System.out.println(status.getUser().getName() + " : " + status.getText());
	        }
	        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {}
	        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {}
	        public void onException(Exception ex) {
	            ex.printStackTrace();
	        }
			@Override
			public void onScrubGeo(long arg0, long arg1) {
				// TODO Auto-generated method stub
				
			}
			@Override
			public void onStallWarning(StallWarning arg0) {
				// TODO Auto-generated method stub
				
			}
	    };
	    TwitterStream twitterStream = new TwitterStreamFactory().getInstance();
	    twitterStream.addListener(listener);
	    // sample() method internally creates a thread which manipulates TwitterStream and calls these adequate listener methods continuously.
	    twitterStream.sample();
	}
			
}
